"use strict";
cc._RF.push(module, 'bee6alUiDRD7aZoPUL7YQOU', 'recordVoiceChange');
// scripts/O1ModuleRes/control/recordVoiceChange.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RECORD_VOICE_STATE = void 0;
/**
 * 录音和变声合集预制
 * */
var btButton_1 = require("./btButton");
var gameEngine_1 = require("../../engines/gameEngine");
var RECORD_VOICE_STATE;
(function (RECORD_VOICE_STATE) {
    RECORD_VOICE_STATE[RECORD_VOICE_STATE["NULL"] = 0] = "NULL";
    RECORD_VOICE_STATE[RECORD_VOICE_STATE["READY"] = 1] = "READY";
    RECORD_VOICE_STATE[RECORD_VOICE_STATE["RECORD"] = 2] = "RECORD";
    RECORD_VOICE_STATE[RECORD_VOICE_STATE["OVER"] = 3] = "OVER";
    RECORD_VOICE_STATE[RECORD_VOICE_STATE["PLAY"] = 4] = "PLAY";
})(RECORD_VOICE_STATE = exports.RECORD_VOICE_STATE || (exports.RECORD_VOICE_STATE = {}));
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var recordVoiceChange = /** @class */ (function (_super) {
    __extends(recordVoiceChange, _super);
    function recordVoiceChange() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        // LIFE-CYCLE CALLBACKS:
        _this.btList = null;
        _this.effectBtNode = null;
        _this.lbState = null;
        _this.editInput = null;
        _this.m_currState = RECORD_VOICE_STATE.READY;
        _this.m_recordTime = 0;
        _this.m_effectList = [
            { name: '调皮猴', numScale: 0.55 },
            { name: '机灵兔', numScale: 0.75 },
            { name: '复读机', numScale: 1 },
            { name: '憨憨象', numScale: 1.25 },
            { name: '老怪物', numScale: 1.5 },
        ];
        _this.m_timeBind = null;
        return _this;
    }
    recordVoiceChange.prototype.onLoad = function () {
        //
        this.OnLoadSetBts();
    };
    recordVoiceChange.prototype.start = function () {
        this.m_currState = RECORD_VOICE_STATE.READY;
    };
    recordVoiceChange.prototype.getTimeFunction = function () {
        if (this.m_timeBind == null) {
            this.m_timeBind = this.OnTimer.bind(this);
        }
        return this.m_timeBind;
    };
    recordVoiceChange.prototype.OnTimer = function () {
        this.m_recordTime++;
    };
    recordVoiceChange.prototype.OnBtnStartRecordVoice = function () {
        if (this.m_currState != RECORD_VOICE_STATE.NULL &&
            this.m_currState != RECORD_VOICE_STATE.READY &&
            this.m_currState != RECORD_VOICE_STATE.OVER) {
            gameEngine_1.default.getModules().uiControlModule.showMessageBox('还不能开始录音');
            return;
        }
        gameEngine_1.default.getServices().miniGameSrv.getAppApiInstance().StartRecordSound();
        this.m_currState = RECORD_VOICE_STATE.RECORD;
        this.m_recordTime = 0;
        this.schedule(this.getTimeFunction(), 1);
    };
    recordVoiceChange.prototype.OnBtnStopRecordVoice = function () {
        var _this = this;
        if (this.m_currState != RECORD_VOICE_STATE.RECORD) {
            gameEngine_1.default.getModules().uiControlModule.showMessageBox('还没有开始录音');
            return;
        }
        this.unschedule(this.getTimeFunction());
        gameEngine_1.default.getServices().miniGameSrv.getAppApiInstance().StopRecordSound(function () {
            _this.m_currState = RECORD_VOICE_STATE.OVER;
        });
    };
    recordVoiceChange.prototype.OnBtnExit = function () {
        this.node.destroy();
    };
    recordVoiceChange.prototype.OnBtnPlaySetNum = function () {
        this.OnBtnListEffect({ name: '手动调', numScale: Number(this.editInput.string) });
    };
    recordVoiceChange.prototype.OnBtnListEffect = function (data) {
        var _this = this;
        if (this.m_currState != RECORD_VOICE_STATE.OVER) {
            if (this.m_currState == RECORD_VOICE_STATE.PLAY) {
                gameEngine_1.default.getModules().uiControlModule.showMessageBox('正在播放中');
            }
            else {
                gameEngine_1.default.getModules().uiControlModule.showMessageBox('没有录音操作');
            }
            return;
        }
        this.m_currState = RECORD_VOICE_STATE.PLAY;
        gameEngine_1.default.getServices().miniGameSrv.getAppApiInstance().PlayLastRecordSound(data.numScale, function () {
            _this.m_currState = RECORD_VOICE_STATE.OVER;
        }, function () {
            _this.m_currState = RECORD_VOICE_STATE.OVER;
        });
    };
    recordVoiceChange.prototype.OnLoadSetBts = function () {
        var _this = this;
        var _loop_1 = function (i) {
            var data = this_1.m_effectList[i];
            var currNode = this_1.effectBtNode;
            if (i > 0) {
                currNode = cc.instantiate(currNode);
                this_1.btList.addChild(currNode);
            }
            var currBt = currNode.getComponent(btButton_1.default);
            currBt.setButtonText(data.name);
            currNode.off('click');
            currNode.on('click', function () {
                _this.OnBtnListEffect(data);
            });
        };
        var this_1 = this;
        for (var i = 0; i < this.m_effectList.length; i++) {
            _loop_1(i);
        }
    };
    recordVoiceChange.prototype.OnUpdateState = function () {
        switch (this.m_currState) {
            case RECORD_VOICE_STATE.NULL: {
                this.lbState.string = '等待录音';
            }
            case RECORD_VOICE_STATE.READY: {
                this.lbState.string = '播放完毕';
                break;
            }
            case RECORD_VOICE_STATE.RECORD: {
                this.lbState.string = "\u5F55\u97F3\u4E2D:[" + this.m_recordTime + "s]";
                break;
            }
            case RECORD_VOICE_STATE.OVER: {
                this.lbState.string = "\u5F55\u97F3\u5B8C\u6BD5";
                break;
            }
            case RECORD_VOICE_STATE.PLAY: {
                this.lbState.string = "\u6B63\u5728\u64AD\u653E";
                break;
            }
        }
    };
    recordVoiceChange.prototype.update = function (dt) {
        this.OnUpdateState();
    };
    __decorate([
        property(cc.Node)
    ], recordVoiceChange.prototype, "btList", void 0);
    __decorate([
        property(cc.Node)
    ], recordVoiceChange.prototype, "effectBtNode", void 0);
    __decorate([
        property(cc.Label)
    ], recordVoiceChange.prototype, "lbState", void 0);
    __decorate([
        property(cc.EditBox) //输入框
    ], recordVoiceChange.prototype, "editInput", void 0);
    recordVoiceChange = __decorate([
        ccclass
    ], recordVoiceChange);
    return recordVoiceChange;
}(cc.Component));
exports.default = recordVoiceChange;

cc._RF.pop();